package com.jimmy.medical.base.impl;

import com.jimmy.medical.base.CrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;

import javax.transaction.Transactional;
import java.io.Serializable;

@NoRepositoryBean
public class CrudServiceImpl<Rep extends CrudRepository<T, ID>, T, ID extends Number> implements CrudService<Rep, T, ID> {
    @Autowired
    protected Rep repository;

    @Override
    public <S extends T> S save(S var1) {
        return repository.save(var1);
    }

    @Override
    public <S extends T> Iterable<S> save(Iterable<S> var1) {
        return repository.save(var1);
    }

    @Override
    public T findOne(ID var1) {
        return repository.findOne(var1);
    }

    @Override
    public boolean exists(ID var1) {
        return repository.exists(var1);
    }

    @Override
    public Iterable<T> findAll() {
        return repository.findAll();
    }

    @Override
    public long count() {
        return repository.count();
    }

    @Override
    public void delete(ID var1) {
        repository.delete(var1);
    }

    @Override
    @Transactional
    public void deleteByKeys(Iterable<? extends ID> keys) {
        for(ID item : keys) {
            delete(item);
        }
    }

    @Override
    public void delete(T var1) {
        repository.delete(var1);
    }

    @Override
    public void delete(Iterable<? extends T> var1) {
        repository.delete(var1);
    }

    @Override
    public void deleteAll() {
        repository.deleteAll();
    }
}
